#include "SDK.h"
#include "PCMPlayer.h"

Error _OtterSDK::DropPCMDevice() {
    return PCM->Drop();
}
Error _OtterSDK::UnloadPlayer() {
	if (PCM)
		delete PCM;
	return Error();
}
Error _OtterSDK::UnloadCodec() {
	if (Codec)
		delete Codec;
	return Error();
}
Error _OtterSDK::LoadCodec(std::string CodecName) {
	if (!PCM)
		Codec = new MusicCodec(std::string("a.mp3"));
	else
		return Error("SDK.h", "Codec Creation Error", "Codec already created", 1);
	return Error();
}
Error _OtterSDK::LoadPlayer(std::string CodecName) {
	if (!PCM)
		PCM = new PCMPlayer();
	else
		return Error("SDK.h", "PCM Handler Creation Error", "PCM player already created", 1);
	return Error();
}
void* StartPCMT(void* data) {
    PCMPlayer* PCM = new PCMPlayer();
    OtterSDK->ReportPCMConstruction(PCM);
    PCM->Play();
}
void* StartCodecT(void* data) {
    MusicCodec* Codec = new MusicCodec(std::string("a.mp3"));
    OtterSDK->ReportCodecConstruction(Codec);
    Codec->BeginDecoding();
}
Error _OtterSDK::Play(std::string FileName) {
	Codec->ChangeFile(FileName);
	if (!PCMRunning)
		pthread_create(&PCMThread, NULL, StartPCMT, (void*)PCM);
	if (!CodecRunning)
		pthread_create(&CodecThread, NULL, StartCodecT, (void*)Codec);
	return Error();
}
